<!-- 
 @Author: LW  
 @Date: 2021-01-08 11:30:38  
 @function: 信息回复 
 -->
<template>
  <div>
    <!-- ref相当于Id:model是表单内容-->
    <el-form
      label-width="120px"
      ref="modifyInfo"
      :rules="formInfoRules"
      :model="formInfo"
    >
      <el-row>
        <el-col :span="24">
          <el-form-item label="消息标题："  prop="title">
            <el-input
              v-model="formInfo.title"
              autocomplete="off"
              maxlength="18"
              size="mini"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="消息内容：" prop="content">
            <el-input
              type="textarea"
              v-model="formInfo.content"
              rows="6"
              autocomplete="off"
              maxlength="200"
              show-word-limit
              size="mini"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer " class="el-dialog__footer">
      <el-button size="mini" @click="closeDialog()">取消</el-button>
      <el-button
        size="mini"
        type="primary"
        :loading="loading"
        @click="submitForm('modifyInfo')"
        >保存</el-button>
    </div>
  </div>
</template>
<script>

import FirstPageHttp from "@/api/first/index"; //http

//定义变量
const {
  replayMassage, //回复消息
} = FirstPageHttp;

export default {
  //组件实例的作用域是孤立的。这意味着不能 (也不应该) 在子组件的模板内直接引用父组件的数据。要让子组件使用父组件的数据，需要通过子组件的 props 选项
  //在模板中，要动态地绑定父组件的数据到子模板的 props，与绑定到任何普通的HTML特性相类似，就是用 v-bind。每当父组件的数据变化时，该变化也会传导给子组件
  props: ["formInfo"], //父界面v-bind:editInfo一致
  components: {},
  data() {
    return {
      loading: false, //是显示加载
      //验证对象，由Rules结尾
      formInfoRules: {
        title: [
          {
            required: true,
            min: 1,
            max: 18,
            message: "标题不能为空，最大长度为18",
            trigger: "blur",
          },
        ],
        content: [
          {
            required: true,
            message: "消息内容不能为空",
            trigger: "blur",
          },
        ],
      }
    };
  },
  /**html加载完成之前，执行。执行顺序：父组件-子组件 */
  created() {},
  /**[页面初始化方法]html加载完成后执行。执行顺序：子组件-父组件*/
  mounted() {},
  methods: {
    //关闭增加弹出框
    closeDialog() {
      this.$emit("callBack", null);
    },
    //保存信息
    submitForm(modifyRef) {
      let self = this;
      this.$refs[modifyRef].validate((valid) => {
        if (valid) {
          let par={
              user_ids: [self.formInfo.receiver_id],
              title: self.formInfo.title,
              content: self.formInfo.content
          };
          replayMassage(par).then((response) => {
            let data = response.data;
            if (data.Code === 1000) {
              self.$emit("callBack", self.formInfo.id);
            } else {
              self.$messageTip.warning(data.Msg); 
            }
          });
        } else {
          return false;
        }
      });
    },
  },
};
</script>